// NOTE: You need to manually change the package name on the next line and in the line within the main function.
// This will be automated in future versions once my Netbeans powers have developed...
package netbeans_processing_template;


import processing.core.PApplet;
import processing.core.PImage;
import tuioZones.TUIOzoneCollection;

/**
 *
 */
public class Applet extends PApplet {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        PApplet.main(new String[]{"netbeans_processing_template.Main"});
    }
    private TUIOzoneCollection zones;
    private PImage b;
    private float r;

    public void setup() {
        size(1280,700,OPENGL);
        // create a draggable, throwable, and scalable zone for a photo
        zones=new TUIOzoneCollection(this);
        zones.setZone("zone1", width/2,height/2,100,100);
        zones.setZoneParameter("zone1","DRAGGABLE",true);
        zones.setZoneParameter("zone1","THROWABLE",true);
        //zones.setZoneParameter("zone1","SCALABLE",true);
        zones.setZoneParameter("zone1","ROTATABLE",true);

        b = loadImage("Man.jpg");
        noFill();
        smooth();
        loop();

        r = 1;        
    }

    public void draw() {
        background(0);
        createPlayfield();

        int[][] coord=zones.getPoints();
        stroke(100,100,100);
        strokeWeight(1);
        if (coord.length>0){
          for (int i=0;i<coord.length;i++){
            ellipse(coord[i][0],coord[i][1],20,20);
            /*int [][] trail=zones.getTrail(coord[i][2]);
            if (trail.length>1){
              for (int j=1;j<trail.length;j++){
                line(trail[j][0],trail[j][1],trail[j-1][0],trail[j-1][1]);
                ellipse(trail[j][0],trail[j][1],5,5);
                println(trail[j][2] + "," + trail[j][3]);
              }
            }*/
          }
        }

        //this.translate(zones.getZoneX("zone1"),zones.getZoneY("zone1"));
        r += 0.1;
        if ((zones.getTranslation()[0]==0) || (zones.getTranslation()[1] == 0)) {
            translate(zones.getZoneX("zone1"),zones.getZoneY("zone1"));
        } else {
            translate(zones.getTranslation()[0],zones.getTranslation()[1]);
        }
        
        this.rotate(-zones.getRotationAngle());

        image(b,0,0,zones.getZoneWidth("zone1"),zones.getZoneHeight("zone1"));
        redraw();
    }

    void createPlayfield() {
        //players box, alwas in the middle of a side
        fill(240,29,36);
        rect(width/2-(width/8),1,width/4,height/10);
        fill(57,175,83);
        rect(width-(height/10)-1,height/2-(width/8),height/10,width/4);
        fill(237,203,67);
        rect(width/2-(width/8),height-(height/10)-1,width/4,height/10);
        fill(18,250,209);
        rect(1,height/2-(width/8),height/10,width/4);
    }
}
